package com.online.edu.course.controller;


import com.online.edu.course.utils.FileStoreUtil;
import com.online.edu.util.core.Result;
import com.online.edu.util.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

/**
 * <p>
 * 文件存储表 前端控制器
 * </p>
 *
 * @author world
 * @since 2021-07-30
 */
/*@Api(tags = "文件上传接口测试")
@RestController
@RequestMapping("/course/file")
public class FileController {

    @Autowired
    FileStoreUtil client;

    //上传文件到服务端
    @ApiOperation("文件上传")
    @PostMapping("/upload")
    public Result upload(MultipartFile file){
        //设置文件上传前面的拼接地址
        StringBuilder url = new StringBuilder("http://121.43.108.189:8080/");
        if (file.isEmpty()){
            //空文件处理
            return Result.error("上传失败！");
        }
        else {
            try {
                InputStream inputStream = file.getInputStream();
                String extName = StringUtil.getFileExtName(file.getOriginalFilename());
                String uploadPath = client.uploadFile(inputStream, extName);
                url.append(uploadPath);
            } catch (IOException e) {
                e.printStackTrace();
            }
            return Result.success("上传成功！",url);
        }
    }
}*/
